package com.usian.user.utils;

import com.alibaba.fastjson.JSON;
import feign.template.Template;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

public class YongYouYunUtils {

    private static final String IDCARDOCR = "079055baee534e038b7121a283d6a7cd";
    private static final String IDENTITYAPICODE = "35a8c266c4bc46a8982e9ca9a1b91eba";

    public static ResponseEntity<String> IdcardOCR(Map<String, String> params){

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("apicode",IDCARDOCR);
        httpHeaders.setContentType(MediaType.APPLICATION_JSON); // json
//        Map<String,String> map = new HashMap<>();
//        map.put("image","https://hmtt122.oss-cn-shanghai.aliyuncs.com/demo_idcard.png");
//        map.put("imageType","URL");
//        map.put("ocrType","0");
        HttpEntity<String> formEntry = new HttpEntity<>(JSON.toJSONString(params), httpHeaders); // 封装请求参数
        ResponseEntity<String> response = restTemplate.postForEntity("https://api.yonyoucloud.com/apis/dst/IdcardOCR/IdcardOCR", formEntry, String.class);// 发送一个post请求
        System.out.println(response);
        // 只要分数
        return response;
    }

    /**
     * params.put("idNumber", "?"); 身份证号
     * params.put("userName", "?"); 身份证姓名
     * @return
     */
    public static ResponseEntity<String> matchIdentity(Map<String,String> params){
        // 路径  头信息   请求体   请求方式   返回值
        RestTemplate restTemplate = new RestTemplate();
        //头信息
        HttpHeaders httpHeaders = new HttpHeaders();
        // 内容类型  编码格式
        httpHeaders.add("apicode",IDENTITYAPICODE);
        httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
        // 设置请求参数
//        Map<String,String> params = new HashMap<>();
//        params.put("idNumber", "210103195103222113");
//        params.put("userName", "王东镇");
        //设置请求体
        HttpEntity<String> formEntry = new HttpEntity<>(JSON.toJSONString(params), httpHeaders);
        ResponseEntity<String> response = restTemplate.postForEntity("https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity",formEntry,String.class);
        return response;
    }



}
